'''
Created on Mar 3, 2011

@author: oabalbin
'''
import logging
#import argparse
import os
import sys

from optparse import OptionParser
from job_runner import qsub_cac, qsub_loc, run_local
from config import ExomePipelineConfig, ExomeAnalysisConfig
import run_lane
from bam_cleaner import bam_cleaner_samples
import exome.gatk_cluster.reads_realignment_job as rra
import exome.snps_callers.snps_byGatk as gtk
import exome.snps_callers.snps_bySamTools3 as sst


def main_variantCalls(run_parameters,lane_deps,\
                      analysis, config, num_processors, runfunc, recal_deps):
    
    # Run parameters
    do_recalibration, quick_dirty, do_paired_samples, multi_samples = \
    run_parameters.do_recal, run_parameters.quick_dirty, run_parameters.paired_samples, run_parameters.multi_samples

    # Call Variants Step
    recal_deps, gtk_deps, sst_deps=[],[],[]
    no_recal_deps=[]

    
    if do_recalibration and quick_dirty: 
    
        use_recal_files=False
    
        recal_deps.extend(rra.fast_lane_level_processing(analysis, config, num_processors, runfunc, lane_deps))
        no_recal_deps.extend( bam_cleaner_samples(analysis, config, num_processors, runfunc, lane_deps) )
    
        if do_paired_samples:
            gtk_deps.extend(gtk.snps_calling_pairedSamples(analysis, config, num_processors, runfunc, recal_deps))
            sst_deps.extend(sst.snps_calling_pairedSamples(analysis, config, do_recalibration, runfunc, recal_deps))
            sst_deps.extend(sst.snps_calling_pairedSamples(analysis, config, use_recal_files, runfunc, no_recal_deps))
                    
        elif multi_samples:
            # 24-1-11: Need to finish those functions
            gtk_deps.extend(gtk.snps_calling_multipleSamples(analysis, config, num_processors, runfunc, recal_deps))
            sst_deps.extend(sst.snps_calling_multipleSamples(analysis, config, do_recalibration, runfunc, recal_deps))
            sst_deps.extend(sst.snps_calling_multipleSamples(analysis, config, use_recal_files, runfunc, no_recal_deps))


    elif do_recalibration and not quick_dirty:
        recal_deps.extend(rra.fast_lane_level_processing(analysis, config, num_processors, runfunc, lane_deps))
        if do_paired_samples:
            gtk_deps.extend(gtk.snps_calling_pairedSamples(analysis, config, num_processors, runfunc, recal_deps))
            sst_deps.extend(sst.snps_calling_pairedSamples(analysis, config, do_recalibration, runfunc, recal_deps))
            
        elif multi_samples:
            # 24-1-11: Need to finish those functions
            gtk_deps.extend(gtk.snps_calling_multipleSamples(analysis, config, num_processors, runfunc, recal_deps))
            sst_deps.extend(sst.snps_calling_multipleSamples(analysis, config, do_recalibration, runfunc, recal_deps))
                  
    elif quick_dirty and not  do_recalibration:
        
        use_recal_files=False
        no_recal_deps.extend( bam_cleaner_samples(analysis, config, num_processors, runfunc, lane_deps) )
        ###### Modify here to use the BAM files not with out recalibration        
        if do_paired_samples:
            sst_deps.extend(sst.snps_calling_pairedSamples(analysis, config, use_recal_files, runfunc, no_recal_deps))
        elif multi_samples:
            sst_deps.extend(sst.snps_calling_multipleSamples(analysis, config, use_recal_files, runfunc, no_recal_deps))
    
    
    return gtk_deps, sst_deps
